/*
 * @Author: White
 * @description: vuex
 * @LastEditTime: 2021-09-01 09:56:25
 */

import { createStore } from 'vuex'
import { getToken, remove } from '@/utils/localstrong' // 按需导入要使用的方法

export default createStore({
  state: {
    userInfo: getToken('userInfo') || [],  //  登录的用户信息
    currentSong: undefined,  //  当前播放歌曲
    player: false,
    theme: getToken('theme') || {},  //默认主题
    songInfoDialog: false  //歌曲详情弹窗
  },
  getters: {
    // 获取登录状态
    userInfo: (state) => state.userInfo,
    currentSong: (state) => state.currentSong,
    player: (state) => state.player,
    themeColor: (state) => state.theme,
    songInfoDialog: (state) => state.songInfoDialog
  },
  mutations: {
    // 保存登录状态
    userInfo(state, data) {
      state.userInfo = data
    },
    // 退出当前账号
    loginout(state, data) {
      remove('userInfo')
      state.userInfo = []
    },
    // 播放歌曲
    setCurrentSong(state, data) {
      state.player = true
      state.currentSong = data
    },
    // 修改主题色
    setTheme(state, data) {
      state.theme = data
    },
    setPlayer(state, val) {
      state.player = val
    },
    setSongInfoDialog(state) {
      state.songInfoDialog = !state.songInfoDialog
    }
  }
})
